//
//  TJTransferRecordCell.m
//  Teleport
//
//  Created by xtjun on 2020/6/13.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJTransferRecordCell.h"


@interface TJTransferRecordCell()

@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UILabel *timeLabel;
@property (strong, nonatomic) UILabel *numberLabel;

@property (strong, nonatomic) UILabel *feeLabel;

@end

@implementation TJTransferRecordCell

- (void)settingSubView {
 
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = UIColor_Hex(0xf2f2f2);
      
    UIView *tj_contentView = [UIView tj_addToView:self.contentView];
     tj_contentView.backgroundColor = UIColor.whiteColor;
    [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(5);
        make.left.right.offset(0);
        make.bottom.offset(0);
    }];
    
    _nameLabel = [UILabel lableWithSuperView:tj_contentView font:UIFont_Px(15) color:UIColor_Hex(0x111111) title:@"" textAlignment:NSTextAlignmentLeft];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.top.offset(10);
    }];
    
    _timeLabel = [UILabel lableWithSuperView:tj_contentView font:UIFont_Px(13) color:UIColor_Hex(0x999999) title:@"" textAlignment:NSTextAlignmentLeft];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.bottom.offset(-10);
    }];
    
    _numberLabel = [UILabel lableWithSuperView:tj_contentView font:MediumFont(15) color:UIColor_Hex(0x999999) title:@"" textAlignment:NSTextAlignmentLeft];
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-16);
        make.top.equalTo(_nameLabel);
    }];
    
    
    _feeLabel = [UILabel lableWithSuperView:tj_contentView font:MediumFont(13) color:UIColor_Hex(0x999999) title:@"" textAlignment:NSTextAlignmentLeft];
       [_feeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           make.right.offset(-16);
           make.top.equalTo(_timeLabel);
       }];
    _feeLabel.textColor = UIColor.darkGrayColor;
        
}

- (void)setModel:(TJTransferRecordModel *)model {
    _model = model;
    
    NSInteger type;
    if ([model.toUser isEqualToString: TJUserInfo.readInfo.userId]) {//转入
        type = 1;
    }else{
         type = 2;
    }
    _nameLabel.text = [NSString stringWithFormat:@"%@%@|UID:%@", type == 1 ? @"转入".localizedString : @"转出".localizedString, model.currency,type == 1 ? model.fromUUID :  model.toUUID];
    
    _timeLabel.text = [self convertStrToTime:model.createTime];
    _numberLabel.text = [NSString stringWithFormat:@"%@%@", type == 1 ? @"+" : @"-",model.num];
    _numberLabel.textColor = type == 1 ? UIColor_Hex(0xDA2629) : UIColor_Hex(0x0ED485);
    _feeLabel.text = [NSString stringWithFormat:@"手续费: -%@", model.fee];
}
- (NSString *)convertStrToTime:(NSString *)timeStr {
    long long time=[timeStr longLongValue]/1000;
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString*timeString=[formatter stringFromDate:date];
    return timeString;
}
@end
